package com.gdth.bank.presenter;

import rx.Subscriber;
import rx.android.schedulers.AndroidSchedulers;
import rx.schedulers.Schedulers;

import com.gdth.bank.model.CJkhxxModel;
import com.gdth.bank.view.CJkhxxView;
import com.gdth.database.bean.TAppBfrjJbxxb;

public class CJkhxxPresenter {
	private CJkhxxView mCJkhxxView;
	private CJkhxxModel mCJkhxxModel;
	
	public CJkhxxPresenter(CJkhxxView mCJkhxxView) {
		this.mCJkhxxView = mCJkhxxView;
		this.mCJkhxxModel = new CJkhxxModel();
	}
	
	public void save(TAppBfrjJbxxb mTAppBfrjJbxxb) {
		mCJkhxxView.showProgressDialog("正在保存...");
		
		mCJkhxxModel.saveCjkhjbxx(mTAppBfrjJbxxb)
			.subscribeOn(Schedulers.io())
			.unsubscribeOn(Schedulers.io())
			.observeOn(AndroidSchedulers.mainThread())
			.subscribe(new Subscriber<TAppBfrjJbxxb>(){

				@Override
				public void onCompleted() {
					// TODO Auto-generated method stub
					mCJkhxxView.hideProgressDialog();
					mCJkhxxView.showMessage("保存成功");
				}

				@Override
				public void onError(Throwable arg0) {
					// TODO Auto-generated method stub
					mCJkhxxView.hideProgressDialog();
					mCJkhxxView.showMessage(arg0.getMessage());
				}

				@Override
				public void onNext(TAppBfrjJbxxb arg0) {
					// TODO Auto-generated method stub
					mCJkhxxView.saveSuccess();
				}
				
			});
	}

	public void updataCjkhjbxx(TAppBfrjJbxxb mTAppBfrjJbxxb) {
		mCJkhxxView.showProgressDialog("正在保存...");

		mCJkhxxModel.updataCjkhjbxx(mTAppBfrjJbxxb)
				.subscribeOn(Schedulers.io())
				.unsubscribeOn(Schedulers.io())
				.observeOn(AndroidSchedulers.mainThread())
				.subscribe(new Subscriber<TAppBfrjJbxxb>(){

					@Override
					public void onCompleted() {
						// TODO Auto-generated method stub
						mCJkhxxView.hideProgressDialog();
						mCJkhxxView.showMessage("保存成功");
					}

					@Override
					public void onError(Throwable arg0) {
						// TODO Auto-generated method stub
						mCJkhxxView.hideProgressDialog();
						mCJkhxxView.showMessage(arg0.getMessage());
					}

					@Override
					public void onNext(TAppBfrjJbxxb arg0) {
						// TODO Auto-generated method stub
						mCJkhxxView.updateView(null);
					}

				});
	}
}
